#include "stdafx.h"
#include "XWnd.h"

XWnd::XWnd(LPCWSTR xml): SOUI::SHostWnd(xml) {
}

XWnd::~XWnd() {
}

void XWnd::OnLogin() {

}

void XWnd::OnLogout() {

}

BOOL XWnd::OnInitDialog(HWND wndFocus, LPARAM lInitParam) {
    m_flag = HttpClient::create_req_flag();
    return FALSE;
}

LRESULT XWnd::__OnLogin(UINT uMsg, WPARAM wParam, LPARAM lParam) {
    m_flag = HttpClient::create_req_flag();
    OnLogin();
    OnReqData();
    return 0;
}

LRESULT XWnd::__OnLogout(UINT uMsg, WPARAM wParam, LPARAM lParam) {
    m_flag.reset();
    OnLogout();
    OnDelData();
    return 0;
}

void  XWnd::__OnShowWindow(BOOL bShow, UINT nStatus) {
    SetMsgHandled(FALSE);
    if (bShow) {
        OnReqData();
    } else {
        OnDelData();
    }
}

void XWnd::showStatus(STATUS_TIPS_TYPE status, const SOUI::SStringW &ssTips) {
    if (status == STATUS_TIPS_TYPE::STATUS_EMPTY_CONTENT) {
        auto tb_status_tips = FindChildByName2<SOUI::STabCtrl>(L"tb_status_tips");
        if (tb_status_tips) {
            tb_status_tips->SetVisible(TRUE, TRUE);
            tb_status_tips->SetCurSel(0);
            if (!ssTips.IsEmpty()) {
                tb_status_tips->FindChildByName(L"lb_nodata")->SetWindowTextW(ssTips);
            }
        }
    } else if (status == STATUS_TIPS_TYPE::STATUS_LOADING) {
        auto tb_status_tips = FindChildByName2<SOUI::STabCtrl>(L"tb_status_tips");
        if (tb_status_tips) {
            tb_status_tips->SetVisible(TRUE, TRUE);
            tb_status_tips->SetCurSel(1);
        }
    } else if (status == STATUS_TIPS_TYPE::STATUS_LOAD_ERROR) {
        auto tb_status_tips = FindChildByName2<SOUI::STabCtrl>(L"tb_status_tips");
        if (tb_status_tips) {
            tb_status_tips->SetVisible(TRUE, TRUE);
            tb_status_tips->SetCurSel(2);
        }
    } else if (status == STATUS_TIPS_TYPE::STATUS_LOAD_NEW) {
        auto wnd_load_new = FindChildByName2<SOUI::SWindow>(L"wnd_load_new");
        if (wnd_load_new) {
            wnd_load_new->SetVisible(TRUE, TRUE);
        }
    } else if (status == STATUS_TIPS_TYPE::STATUS_LOAD_MORE) {
        auto wnd_load_more = FindChildByName2<SOUI::SWindow>(L"wnd_load_more");
        if (wnd_load_more) {
            wnd_load_more->SetVisible(TRUE, TRUE);
        }
    }
}

void XWnd::hideStatus() {
    auto tb_status_tips = FindChildByName2<SOUI::STabCtrl>(L"tb_status_tips");
    if (tb_status_tips) {
        tb_status_tips->SetVisible(FALSE, TRUE);
    }
    
    auto wnd_load_new = FindChildByName2<SOUI::SWindow>(L"wnd_load_new");
    if (wnd_load_new) {
        wnd_load_new->SetVisible(FALSE, TRUE);
    }
    
    auto wnd_load_more = FindChildByName2<SOUI::SWindow>(L"wnd_load_more");
    if (wnd_load_more) {
        wnd_load_more->SetVisible(FALSE, TRUE);
    }
}
